import Mock from 'mockjs'

const ClassNum = [30, 50, 47, 60, 110, 23, 45, 112, 76]
let i = 0

const ClassList = []

const baseContent = '@cparagraph'
const image_uri = 'https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3'

function generateRoster(count = ClassNum[i]){
  const roster = []
  for(let j = 0; j < count; j++){
    roster.push(Mock.mock({
      stu_id: '161800'+i+j,
      mch_id: '@string(lower,16)',
      ip_adr: '@ip',
      'status|1': ['正在运行', '已关机', '挂起'],
      detail: baseContent,
    }))
  }
  return roster
}

for(i in ClassNum){
  ClassList.push(Mock.mock({
    classID:'@string(lower,6)',
    name:'@ctitle(3, 5)',
    label:'161800'+'@increment',
    'isOpen|1': [false, true],
    detail: baseContent,
    roster: generateRoster(),
  }))
}
// console.log(ClassList)


export default [
  {
    url: '/teacher/list',
    type: 'get',
    response: config => {
      const { tchID, classID, opened} = config.query

      let mockList = ClassList.filter(item => {
        if (classID && item.classID.indexOf(classID) < 0) return false
        if (opened && !item.isOpen) return false
        return true
      })

      return {
        code: 20000,
        data: {
          total: mockList.length,
          list: mockList
        }
      }
    }
  },

  {
    url: '/teacher/detail',
    type: 'get',
    response: config => {
      const { classID } = config.query
      for (const item of ClassList) {
        if (item.classID === classID) {
          return {
            code: 20000,
            data: item.detail
          }
        }
      }
    }
  },

  {
    url: '/teacher/create',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  },
]

